package com.hmall.search.web;


import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RequestMapping("/search")
@RestController
public class SearchController {
    @Autowired
    private SearchService searchService;

    /**
     * 查询过滤器
     * @param requestParams
     * @return
     */
    @PostMapping("/filters")
    public Map<String, List<String>> getFiltersResult(@RequestBody RequestParams requestParams){
        Map<String, List<String>> map= searchService.getFilters(requestParams);
        return map;
    }


    @PostMapping("/list")
    public PageDTO<ItemDoc> search(@RequestBody RequestParams requestParams) throws Exception {
        return searchService.searchList(requestParams);
    }
}
